<style >
/* 可以设置不同的进入和离开动画 */
/* 设置持续时间和动画函数 */
.slide-fade-enter-active {
  transition: all 1.5s ease;
}

.slide-fade-leave-active {
  transition: all 1.5s cubic-bezier(1.0, 0.5, 0.8, 1.0);
}

.slide-fade-enter,
.slide-fade-leave-to

/* .slide-fade-leave-active for below version 2.1.8 */
  {
  transform: translateX(10px);
  opacity: 0;
}
</style>
<style lang="scss" >
@import '../styles/version1/home_index.scss';
@import '../styles/color.scss';

</style>

<template>
  <div id="home" class="home-container">
    <home-header @changeCollapse="changeCollapse"/>
    <el-container class="home-main" :style="{maxHeight: winH - 40 + 'px'}">
      <el-aside class="home-left " :style="{ width: sideBarWidth + 'px'}" >
        <transition name="slide-fade" >
          <el-menu class="home-left-menu   animated fadeInRight"    :default-active="$route.path" :unique-opened="true" router :collapse="!isCollapse" @select="menuSelect">
            <menu-item v-for="menu in menus"
                       :key="menu.id" :item="menu"
                       :index="menu.id"
                       :isCollapse="isCollapse"
            />
          </el-menu>
        </transition>
      </el-aside>

      <el-main class="home-main-box">

       <tags-view  v-if="loadAll" :isCollapse="isCollapse" />

        <el-row  class="home-main-content" :style="{maxHeight: winH - 100+ 'px',height: winH - 150+ 'px'}"  v-if="loadAll">
          <el-col :span="24">
            <transition name="fade" mode="out-in">
              <keep-alive >
                <router-view ref="routerView" v-if="isRouterAlive" :key="$route.fullPath"></router-view>
              </keep-alive>
            </transition>
          </el-col>
        </el-row>

        <el-row  class="home-main-content" :style="{maxHeight: winH - 100+ 'px',height: winH - 100+ 'px'}"  v-if="!loadAll"
                 v-loading="!loadAll"
                 :element-loading-text="cploadingText"
                 element-loading-spinner="spinner-user"
                 element-loading-background="rgba(0, 0, 0, 0)"
                 element-loading-custom-class="spinner-custom"
        >
        </el-row>
      </el-main>
    </el-container>

    <!--表单打印-->
    <customDrawer
      :autoHide="false"
      :footer="false"
      title="表单打印"
      :subtitle="dialogPrintTitleAppend"
      :zIndex="88888"
      ref="customDrawerPrintForm"
      :widthPx="666" :heightPx="240"
      >
      <template #content>
        <FortenPrintForm ref="printForm" :param="printFormParam" @printFormClose="$refs.customDrawerPrintForm.hide()" @></FortenPrintForm>
      </template>
    </customDrawer>

    <!--标签打印-->
    <customDrawer
      :autoHide="false"
      :footer="false"
      title="标签打印"
      :zIndex="88888"
      ref="customDrawerPrintLabel"
      @hide="customDrawerPrintLabelHide"
      :widthPx="666" :heightPx="240"
      @confirm="confirmInputConfirm">
      <template #content>
        <FortenPrintLabel ref="printLabelInst" :param="printLabelFormParam"></FortenPrintLabel>
      </template>
    </customDrawer>

    <!--标签打印-设备-->
    <customDrawer
      :autoHide="false"
      :footer="false"
      title="设备标签打印"
      :zIndex="88888"
      ref="customDrawerPrintLabelDevice"
      :widthPx="666" :heightPx="240"
    >
      <template #content>
        <PrintLabelDevice ref="printLabelDeviceInst" :param="printLabelDeviceParam"></PrintLabelDevice>
      </template>
    </customDrawer>


    <!--标签打印列表-非设备-->
    <customDrawer
      :autoHide="false"
      :footer="false"
      title="标签打印"
      placement="right"
      :zIndex="88800"
      ref="customDrawerBarcode"
      v-if="loadAll"
    >
      <template #content>
        <inOrderBarcode ref="barcodeForm"
                        :propLineIdRequired="true"
                        :propPrintOnlyOne="true"
        />
      </template>
    </customDrawer>

    <customDrawer
      :autoHide="false"
      :footer="false"
      title="报表打印"
      :zIndex="88888"
      ref="customDrawerPrintReport"
      :widthPx="666" :heightPx="240"
    >
      <template #content>
        <FortenPrintReport ref="printReportForm" :paramArr="printReportFormParam" @printFormClose="$refs.customDrawerPrintReport.hide()"></FortenPrintReport>
      </template>
    </customDrawer>

    <el-dialog :title="dialogTreeListTitle" :visible.sync="dialogTreeList" width="888px"  >
      <FortenTreeList @printFormClose="fortenTreeListClose"
                      :propTreeProps="propTreeProps"
                      :propQueryUrl="propQueryUrl"
                      :propFieldNodeId="propFieldNodeId"
                      :propFieldLabel="propFieldLabel"
                      :propTreeShowCheckbox="propTreeShowCheckbox"
                      :propOnlyQuery="propOnlyQuery"

      ></FortenTreeList>
    </el-dialog>

    <el-dialog title="PDA预览及打印(docx文件将转换显示，出现乱码请自行下载)" :visible.sync="dialogPDFForm" width="60%"  >
      <iframe :src="pdfUrl"   width="100%" height="400px"  frameborder="0" scrolling="yes" ></iframe>
    </el-dialog>

    <el-drawer title="导入数据"
               :append-to-body="true"
               :visible.sync = "dialogImport"
               :destroy-on-close="true"
               v-if="dialogImport"
               direction="rtl"
               class="label-close"
               size="50%">
      <FortenImport :param="dialogImportParam" @printFormClose="dialogImportClose"></FortenImport>
    </el-drawer>




    <el-drawer :title="dialogMoreTitle"
               :append-to-body="true"
               :visible.sync = "dialogMoreForm"
               :destroy-on-close="true"
               v-if="dialogMoreForm"
               direction="rtl"
               class="label-close"
               size="80%">
      <!-- 数据视图-->
      <indexModel   v-if="dialogMoreType == 'dataview'" :propViewKey="dialogMoreTypeKey"  style="padding: 0px 11px"
                    :propShowClose="true" @closewin ="dialogMoreClose"
                    :propPreQueryWrapper="dialogMoreWrapper"
                    :propViewForm="dialogMoreViewForm"
                    :rowEditParam="dialogMoreRowEditParam"
      />

      <!--报表-->
      <Report v-if="dialogMoreType == 'report'" :propReportKey="dialogMoreTypeKey" style="padding: 0px 11px" :propShowClose="true" @close ="dialogMoreClose" :propQueryWrapper="dialogMoreWrapper"></Report>
    </el-drawer>

    <!--仓库选择-->
    <tableDrawer
      ref="tableDrawerWarehouse"
      refName="tableDrawerWarehouse"
      viewKey="select_warehouse"
      title="请选择仓库"
      :subtitle="selectWrapper.warehouseSubtitle"
      :queryWrapper="selectWrapper.warehouse"
      loadForce
    />

    <!--供应商选择-->
    <tableDrawer
      ref="tableDrawerSupplier"
      refName="tableDrawerSupplier"
      :viewKey="constCommon.viewKeySelect.supplier"
      title="请选择供应商"
      :subtitle="selectWrapper.supplierSubtitle"
      :queryWrapper="selectWrapper.supplier"
      loadForce
    />

    <!--厂商选择-->
    <tableDrawer
      ref="tableDrawerMfg"
      refName="tableDrawerMfg"
      :viewKey="constCommon.viewKeySelect.mfg"
      title="请选择厂商"
      :subtitle="selectWrapper.mfgSubtitle"
      loadForce
    />

    <!--科室选择-->
    <tableDrawer
      ref="tableDrawerDept"
      loadForce
      refName="tableDrawerDept"
      viewKey="select_dept"
      :queryWrapper="selectWrapper.dept"
      title="请选择科室"
      :subtitle="selectWrapper.deptSubtitle"
    />

    <!--科室地址选择-->
    <tableDrawer
      ref="tableDrawerDeptAddress"
      loadForce
      refName="tableDrawerDeptAddress"
      viewKey="base_dept_address_select"
      :queryWrapper="selectWrapper.deptAddress"
      title="请选择科室地址"
      :subtitle="selectWrapper.deptAddressSubtitle"
    />

    <!--试剂组选择-->
    <tableDrawer
      ref="tableDrawerReagentTeam"
      loadForce
      refName="tableDrawerReagentTeam"
      viewKey="base_reagent_team_select"
      :queryWrapper="selectWrapper.reagentTeam"
      title="请选择试剂组"
      :subtitle="selectWrapper.reagentTeamSubtitle"
    />

    <!--商品选择 单选-->
    <tableDrawer
      ref="tableDrawerMatr"
      loadForce
      refName="tableDrawerMatr"
      viewKey="base_matr_select_applydemand"
      :queryWrapper="selectWrapper.matr"
      :propUserParam="selectWrapper.matrPropUserParam"
      title="请选择商品"
      :subtitle="selectWrapper.matrSubtitle"
      :widthPer="80"
      :heightPx="-1"
      :widthPx="-1"
    />

    <!--商品选择 多选-->
    <tableDrawer
      ref="tableDrawerMatrMore"
      loadForce
      refName="tableDrawerMatrMore"
      viewKey="base_matr_select_applydemand"
      :queryWrapper="selectWrapper.matrMore"
      :propUserParam="selectWrapper.matrMorePropUserParam"
      title="请选择商品"
      :subtitle="selectWrapper.matrMoreSubtitle"
      :widthPer="80"
      :heightPx="-1"
      :widthPx="-1"
    />

    <!--商品模板选择-->
    <tableDrawer
      ref="tableDrawerMatrPackTemplet"
      loadForce
      propShowChildCheckbox
      refName="tableDrawerMatrPackTemplet"
      viewKey="base_pack_templet_select"
      :queryWrapper="selectWrapper.matrPackTemplet"
      :propUserParam="selectWrapper.matrPackTempletPropUserParam"
      title="请选择商品模板"
      :subtitle="selectWrapper.matrPackTempletSubtitle"
    />

    <!--商品单位选择-->
    <tableDrawer
      ref="tableDrawerUnit"
      loadForce
      refName="tableDrawerUnit"
      viewKey="base_matr_unit_select"
      :queryWrapper="selectWrapper.unit"
      title="请选择商品单位"
      :subtitle="selectWrapper.unitSubtitle"
    />

    <!--员工选择-->
    <tableDrawer
      ref="tableDrawerStaff"
      loadForce
      refName="tableDrawerStaff"
      viewKey="base_staff"
      title="请选择员工"
      subtitle="所有员工"
      :subtitle="selectWrapper.staffSubtitle"
    />

    <!--患者选择-->
    <tableDrawer
      ref="tableDrawerPatient"
      loadForce
      refName="tableDrawerPatient"
      viewKey="patient_select"
      title="请选择患者"
      :subtitle="selectWrapper.patientSubtitle"
      :widthPer="80"
      :heightPx="-1"
      :widthPx="-1"
    />

    <!--库存选择 单个-->
    <tableDrawer
      ref="tableDrawerStockOne"
      refName="tableDrawerStockOne"
      viewKey="wm_stock_barcode"
      :queryWrapper="selectWrapper.stockOne"
      loadForce
      title="请选择库存记录"
      :subtitle="selectWrapper.stockOneSubtitle"
      :widthPer="80"
      :heightPx="-1"
      :widthPx="-1"
    />

    <!--库存选择 多个-->
    <tableDrawer
      ref="tableDrawerStock"
      refName="tableDrawerStock"
      viewKey="wm_stock_barcode"
      :queryWrapper="selectWrapper.stock"
      loadForce
      title="请选择库存记录"
      :subtitle="selectWrapper.stockSubtitle"
      :propUserParam="selectWrapper.stockPropUserParam"
      :widthPer="80"
      :heightPx="-1"
      :widthPx="-1"
    />

    <!--库存推荐选择-->
    <tableDrawer
      ref="tableDrawerStockApplyDemand"
      refName="tableDrawerStockApplyDemand"
      viewKey="wm_stock_applydemand"
      :queryWrapper="selectWrapper.stockApplyDemand"
      :propUserParam="selectWrapper.stockApplyDemandPropUserParam"
      loadForce
      title="请选择库存记录"
      :subtitle="selectWrapper.stockApplyDemandSubtitle"
    />

    <!--采购订单选择-->
    <tableDrawer
      ref="tableDrawerPurchaseOrder"
      refName="tableDrawerPurchaseOrder"
      viewKey="purchase_order_select"
      :queryWrapper="selectWrapper.purchaseOrder"
      loadForce
      title="请选择采购订单"
      :subtitle="selectWrapper.purchaseOrderSubtitle"
    />

    <!--手术单选择-->
    <tableDrawer
      ref="tableDrawerOprt"
      refName="tableDrawerOprt"
      viewKey="select_oprt_by_patient"
      :queryWrapper="selectWrapper.oprt"
      loadForce
      title="请选择手术单"
      :subtitle="selectWrapper.oprtSubtitle"
    />

    <!--手术单选择-->
    <tableDrawer
      ref="tableDrawerHisBill"
      refName="tableDrawerHisBill"
      viewKey="dept_his_bill"
      :queryWrapper="selectWrapper.hisBill"
      loadForce
      title="请选择HIS计费记录"
      :subtitle="selectWrapper.hisBillSubtitle"
    />

    <!--库位选择-->
    <tableDrawer
      ref="tableDrawerLocation"
      refName="tableDrawerLocation"
      viewKey="base_location_select"
      :queryWrapper="selectWrapper.location"
      loadForce
      title="请选择库位"
      :subtitle="selectWrapper.locationSubtitle"
    />

    <!--设备选择 多个-->
    <tableDrawer
      ref="tableDrawerDeviceMore"
      refName="tableDrawerDeviceMore"
      viewKey="device_ledger_select"
      :queryWrapper="selectWrapper.deviceMore"
      loadForce
      title="请选择设备"
      :subtitle="selectWrapper.deviceMoreSubtitle"
      :widthPer="80"
      :heightPx="-1"
      :widthPx="-1"
      :propUserParam="selectWrapper.deviceMorePropUserParam"
    />

    <!--设备选择 单个-->
    <tableDrawer
      ref="tableDrawerDeviceOne"
      refName="tableDrawerDeviceOne"
      viewKey="device_ledger_select"
      :queryWrapper="selectWrapper.deviceOne"
      loadForce
      title="请选择设备"
      :subtitle="selectWrapper.deviceOneSubtitle"
      :widthPer="80"
      :heightPx="-1"
      :widthPx="-1"
      :propUserParam="selectWrapper.deviceOnePropUserParam"
    />

    <!--机构选择-->
    <treeOfficeDrawer ref="treeOfficeDrawer"/>

    <!--提示确认框 成功-->
    <customDialog ref="customAlertSuccess" theme="success"/>

    <!--提示确认框 失败-->
    <customDialog ref="customAlertFail" theme="danger"/>

    <!--提示确认框 包含取消按钮-->
    <customDialog ref="customDialogConfirm" theme="warning" cancelBtn="取消" :zIndex="5000"/>

    <!--全局通知-->
    <t-notification v-show="notificationHome.show" id="notificationHome" style="position: absolute;right: 20px;  bottom: 12px; z-index: 999999" ref="notificationHome" theme="info">
      <template #title>
        <div>{{notificationHome.title}} <!--<small>消息通知副标题</small>--></div>
        <small style="    font-size: 12px;line-height: 12px;" v-show="strings.isNotBlank(notificationHome.subTitle)" v-html="notificationHome.subTitle">{{notificationHome.subTitle}}</small>
      </template>
      <template #content>
        <div v-html="notificationHome.content"></div>
      </template>
      <template #footer v-show="notificationHome.btnShow">
        <div class="t-notification__detail">
          <t-button class="t-notification__detail-item" theme="primary" variant="text" @click="notificationHomeClick">
            {{notificationHome.btnText}}
          </t-button>
        </div>
      </template>
    </t-notification>

    <!--全局确认输入框，只有一个文本域输入-->
    <customDrawer :autoHide="false" :title="confirmInputForm.title" ref="confirmInputDrawer" :widthPx="500" :heightPx="250" @confirm="confirmInputConfirm">
      <template #content>
        <customForm :labelWidth="80" ref="confirmInputForm" :rules="confirmInputForm.rules"  :data="confirmInputForm" style="margin-top: 30px">
          <template #content>
            <customFormItem
              label="说明"
              name="remark"
              :parent="_self"
              :form="confirmInputForm"
              :type="constCommon.formItemType.textarea.name"
              :config="{minRows: 3, autosize: false, maxRows: 5}"
              fullWidth
            />
          </template>
        </customForm>
      </template>
    </customDrawer>

    <!--    pdf预览窗口-->
    <customDrawer :autoHide="false" title="PDF文件预览" ref="customDrawerPdf" :hideConfirm="true" attach="body">
      <template #content>
        <pdf  :src="pdfUrl"/>
      </template>
    </customDrawer>

    <!--    调价明细报表-->
    <customDrawer :autoHide="false" title="调价明细" :subtitle="selectWrapper.reportAdjustSubtitle" ref="customDrawerReportAdjust" :footer="false" attach="body" :widthPer="90">
      <template #content>
        <Report
          :propHideHeader="true"
          :propShowClose="true"
          @close="$refs.customDrawerReportAdjust.hide()"
          :propNoAutoFetchData="true"
          ref="customDrawerReportAdjustReport"
          propReportKey="price_adjustment_all"
        />
      </template>
    </customDrawer>

    <!--    新增数据后并选择-->
    <customDrawer   :title="'新增' + selectCreateFormBusType"   ref="selectCreateFormWin" :footer="false" attach="body" placement="right" >
      <template #content>
        <!-- 明细界面按钮区域 -->
        <div  class="button-box-top">
          <customSpace>
            <template #content>
              <customButton  title="保存" theme="primary" size="medium" @click="createFormWinFun('save')"/>
              <customButton  title="关闭" theme="default" size="medium"  @click="createFormWinFun('close')"/>
            </template>
          </customSpace>
        </div>
        <component
          v-if="selectCreateForm!==null"
          :is="selectCreateForm"
          ref="selectCreateForm"
          :propParent="_self"
          :propStatus="'edit'"
          :propRules="selectCreateFormRules"
        />
      </template>
    </customDrawer>
  </div>
</template>
<script>

import menuItem from '@/components/MenuItem.vue'
import homeHeader from '@/views/HomeHeader.vue'
import TagsView from '@/views/TagsView.vue'
import FortenPrintForm from '@/components/common/FortenPrintForm.vue'
import FortenPrintLabel from '@/components/common/FortenPrintLabel.vue'
import PrintLabelDevice from '@/components/common/PrintLabelDevice.vue'
import FortenPrintReport from '@/components/common/FortenPrintReport.vue'
import FortenImport from '@/components/common/FortenImport.vue'
import inOrderBarcode from '@/views/wm/order-barcode/stock-common.vue'
import Report from '@/components/report/Report.vue'
import indexModel from '@/views/frame/data-view/index-model.vue'
import utilVuex from '../util/utilVuex.js'
import utilSocket from '../util/utilSocket.js'
import treeOfficeDrawer from '@/components/custom/bus/treeOfficeDrawer.vue'
import pdf from 'vue-pdf'


export default {
  provide() {
    return {
      reload: this.reload
    }
  },
  data() {
    return {
      isRouterAlive: true,
      dialogPrintForm: false,
      dialogPrintReportForm: false,
      dialogMoreForm: false,
      dialogImport: false,
      drawerSnPrint: false,
      dialogPDFForm: false,
      dialogTreeList: false,
      setBarcodeVisible: false,
      printFormParam: null,
      printLabelFormParam: null,
      printLabelDeviceParam: null,
      printReportFormParam: null,
      dialogImportParam: null,
      isCollapse: true,
      tabActive: null,
      tabsOpened: [],
      menus: [],
      sideBarWidth: 210,
      logoWidth: '180px',
      dialogPrintTitleAppend: '',
      routes: [
        {
        }
      ],

      //树列表属性
      dialogTreeListTitle: '请选择',
      propTreeProps: undefined,
      propQueryUrl: undefined,
      propFieldNodeId: undefined,
      propFieldLabel: undefined,
      propTreeShowCheckbox: undefined,
      propOnlyQuery: undefined,
      pdfUrl: null,
      dialogMoreType: null,
      dialogMoreTypeKey: null,
      dialogMoreTitle: null,
      dialogMoreWrapper: null,
      dialogMoreViewForm: null,
      dialogMoreRowEditParam: null,
      winH: window.innerHeight,
      menuSearch: '',

      // 消息提醒配置
      notificationHome: {
        show: false,
        btnShow: false,
        title: '系统通知',
        subTitle: '',
        content: '通知内容',
        btnText: '查看详情',
      },

      // 选框查询条件
      selectWrapper: {
        warehouse: null,
        warehouseSubtitle: '',
        supplier: null,
        supplierSubtitle: '',
        mfgSubtitle: '',
        dept: global.$newWrapper().eq('flagDisabled', 0),
        deptSubtitle: '',
        matr: null,
        matrSubtitle: '',
        matrPropUserParam: null,
        matrMore: null,
        matrMoreSubtitle: '',
        matrMorePropUserParam: null,
        unit: null,
        unitSubtitle: '',
        purchaseOrder: null,
        purchaseOrderSubtitle: '',
        deptAddress: null,
        deptAddressSubtitle: '',
        reagentTeam: null,
        reagentTeamSubtitle: '',
        matrPackTemplet: null,
        matrPackTempletSubtitle: '',
        matrPackTempletPropUserParam: null,
        stockApplyDemand: null,
        stockApplyDemandSubtitle: '',
        stockApplyDemandPropUserParam: null,
        stockOne: null,
        stockOneSubtitle: '',
        stock: null,
        stockSubtitle: '',
        stockPropUserParam: {},
        oprt: null,
        oprtSubtitle: '',
        hisBill: null,
        hisBillSubtitle: '',
        location: null,
        locationSubtitle: '',
        deviceMore: null,
        deviceMoreSubtitle: '',
        deviceMorePropUserParam: {},
        deviceOne: null,
        deviceOneSubtitle: '',
        deviceOnePropUserParam: {},
        reportAdjustSubtitle: ''
      },
      loadAll: false,
      getTotal: 0,
      getAdd: 0,
      // 输入确认
      confirmInputForm: {
        title: '系统提示',
        comment: '',
        confirmFun: () => {},
        rules: {
          remark: [{ required: true, message: '请输入原因', trigger: 'blur' }],
        }
      },

      // 标签打印窗口关闭后执行函数
      customDrawerPrintLabelHideFun: null,

      selectCreateForm: null,
      selectCreateFormRules: {},
      selectCreateFormSaveAction: null,
      selectCreateFormAfterSave: null,
      selectCreateFormBusType: '',
    }
  },
  computed: {
    viewsKeepAlive() {
      return true
    },
    cploadingText() {
      return `资源加载中,总计: ${this.getTotal},已加载: ${this.getAdd}`
    }
  },
  created() {
  },
  beforeMount() {
    this.initData()
  },
  mounted() {
    history.pushState(null, null, document.URL)
    window.addEventListener('popstate',  () => {
      history.pushState(null, null, document.URL)
    })

    const that = this
    //窗口变化后
    window.onresize = () => {
      return (() => {
        that.winH = window.innerHeight
      })()
    }
  },
  methods: {
    reload() {
      this.isRouterAlive = false
      this.$nextTick(function () {
        this.isRouterAlive =  true
      })
    },

    //用户登录后进行初始化
    initData() {
      this.utils.afterHomeLoad(this)
      utilSocket.init()
      this.$ajax.get('/user/info').then(res => {
        if (res.success) {
          let data = res.data
          this.$store.dispatch('setCurrentUser', data.currentUser)

          //可用菜单列表
          if (data.menuList && data.menuList.length > 0) {
            let menus = this.utils.convertToTree(data.menuList, {
              rootNode: {id: '0', parentId: '-1', name: '根节点' },
              keyFieldName: 'id',
              parentFieldName: 'parentId',
              labelFieldName: 'title'
            })
            this.menus = menus.length > 0 ? menus[0].children : menus
          }


          //用户状态
          let statePc = JSON.parse(data.user.statePc) || {}
          if (statePc.menu) statePc.menu = JSON.parse(statePc.menu)
          if (statePc.workbenchWarehouse) statePc.workbenchWarehouse = JSON.parse(statePc.workbenchWarehouse)
          this.$store.dispatch('seUserState', statePc)

          //3、工作台配置
          if (statePc.workbenchWarehouse) {
            this.$store.commit('SET_CURRENT_WAREHOUSE', statePc.workbenchWarehouse)
          }

          this.getTotal = utilVuex.getMapSize()
          setTimeout(() => {
            if (!this.loadAll) {
              this.utilMessage.alertFail('资源加载失败，是否刷新重试', () => {
                location.reload()
              })
            }
          }, 60 * 1000)
          utilVuex.syncAll(this, () => {
            global.settings.hospitalName = this.parameters.getSystemHospitalName(this, global.settings.hospitalName)
            this.loadAll = true
            //1、 菜单打开列表
            if (statePc.menu) {
              // eslint-disable-next-line no-plusplus
              for (let index = statePc.menu.length - 1; index >= 0; index--) {
                this.$store.dispatch('addVisitedView', statePc.menu[index])
              }
            }

            //2、打开上一次路由
            if (statePc.routeCurrent) {
              if (this.$router.options.routes.length > 1) {
                let routers = this.$router.options.routes[1].children
                let currentRoute = statePc.routeCurrent.indexOf('/') == 0 ? statePc.routeCurrent.slice(1) : statePc.routeCurrent
                if (routers.filter(rt => rt.path == currentRoute).length > 0) {
                  this.$router.replace({path: statePc.routeCurrent}, () => {
                  })
                }
              }
            }
          })
        }
      })
    },
    //控制左边菜单显示与否
    changeCollapse() {
      if (this.isCollapse) { //当前为展开状态
        this.logoWidth = '200px'
        this.sideBarWidth =  60
      } else {
        this.logoWidth = '180px'
        this.sideBarWidth = 200
      }

      this.isCollapse = !this.isCollapse
      localStorage.setItem('userNavIsCollapse', this.isCollapse)
    },
    menuSelect(index, path) {
    },
    //关闭打印界面
    printReportFormClose() {
      this.dialogPrintReportForm = false
    },
    //关闭树列表选择
    fortenTreeListClose() {
      this.dialogTreeList = false
    },
    //关闭导入窗口
    dialogImportClose() {
      this.dialogImport = false
    },
    //关闭标签窗口
    closeBarcode() {
      this.setBarcodeVisible = false
      this.drawerSnPrint = false
    },
    //打开标签窗口后
    barcodeOpened() {
      this.$refs.barcodeForm.gridSearch()
    },
    //关闭打印界面
    dialogMoreClose() {
      this.dialogMoreForm = false

      if (window.dialogMoreCloseCall) {
        window.dialogMoreCloseCall()
      }
    },
    // 消息右下角按钮点击
    notificationHomeClick() {
      if (this.notificationHome.btnCall) {
        this.notificationHome.btnCall()
      }
      setTimeout(() => {
        this.notificationHome.show = false
      }, 2000)
    },
    // 输入确认框确认
    confirmInputConfirm() {
      if (this.confirmInputForm.confirmFun) {
        this.$refs.confirmInputForm.validate().then(result => {
          if (result === true) {
            this.$refs.confirmInputDrawer.hide()
            this.confirmInputForm.confirmFun(this.confirmInputForm.remark)
            this.confirmInputForm.remark = ''
          }
        })
      }
    },
    // 标签打印窗口关闭后
    customDrawerPrintLabelHide() {
      if (this.customDrawerPrintLabelHideFun) {
        this.customDrawerPrintLabelHideFun()
      }
    },

    openSelectCreateForm(busType, viewKey, formPath,afterSave) {
      let  that = this
      // eslint-disable-next-line import/no-dynamic-require
      require([`@/views/${formPath}`], (target) => {
        that.selectCreateForm = target.default
      })
        .catch(() => {
          that.selectCreateForm = null
        })

      let viewObj = JSON.parse(JSON.stringify(global.utilVuex.getDataviewMap()[viewKey]))
      this.selectCreateFormRules = this.selectCreateFormParseRules(viewObj.rules)
      this.selectCreateFormSaveAction = viewObj.saveEntry
      this.selectCreateFormAfterSave = afterSave
      this.selectCreateFormBusType = busType
      if (this.$refs.selectCreateForm && this.$refs.selectCreateForm.form) {
        this.$refs.selectCreateForm.form = {}
      }
      this.$refs.selectCreateFormWin.show()

     this.$nextTick(() => {
       setTimeout(() => {
         if (this.$refs.selectCreateForm && this.$refs.selectCreateForm.focusFirst) {
           this.$refs.selectCreateForm.focusFirst()
         }
       }, 1500)
     })
    },
    selectCreateFormParseRules(rules) {
      const obj = {}
      Object.keys(rules).forEach((objKey) => {
        const tmp = []
        rules[objKey].forEach((item) => {
          try {
            if (item) {
              if (item.constructor !== String) {
                /**
                 * @Description：兼容tdesign，转换下规则，不然会报错
                 * @Author wyt
                 * @Date 2023-09-27
                 */
                if (item.pattern) {
                  item.pattern = new RegExp(item.pattern)
                }
                tmp.push(item)
              } else {
                tmp.push(JSON.parse(item))
              }
            }

          } catch(e) {
            console.error('解析规则失败，原因如下')
            console.error(e)
          }
        })
        obj[objKey] = tmp
      })
      return obj
    },
    createFormWinFun(funType) {
     switch (funType) {
       case 'save': {
         this.$refs.selectCreateForm.$refs.editForm.validate().then((result) => {
           if (result && result == true) {
             this.utilVue.loadShow(true)
             this.$ajax
               .post(this.selectCreateFormSaveAction, this.$refs.selectCreateForm.form)
               .then((resp) => {
                 this.utilVue.loadHide()
                 if (resp.code == 0) {
                   this.utilMessage.success(resp.msg)
                   if (this.selectCreateFormAfterSave) {
                     this.selectCreateFormAfterSave(resp.data)
                   }
                   this.$refs.selectCreateFormWin.hide()
                 }
               })
           }
         })
         break
       }
       case 'close': {
         this.$refs.selectCreateFormWin.hide()
         break
       }
     }
    }
  },
  watch: {
    //路由变化后刷新数据
    $route(to, from) {
      if (this.$refs.routerView) {
        setTimeout(() => {
          if (this.$refs.routerView.menuActiveCall) {
            this.$refs.routerView.menuActiveCall()
          }
          if (this.$refs.routerView && this.$refs.routerView.name == 'report') { //单个报表
            // this.$refs.routerView.handleQueryClick()
          } else if (this.$refs.routerView && this.$refs.routerView.name == 'reportMore') { //多个报表
            // this.$refs.routerView.fetchDataCurr()
          } else if (this.$refs.routerView) {
            //类型为dataview，并且只有一个dataview的，则一般为列表
            if (
              !this.$refs.routerView.menuActiveCall
              &&this.$refs.routerView.$children
              && this.$refs.routerView.$children.length == 1
              && this.$refs.routerView.$children[0].name == 'dataview'
            ) {
              this.$refs.routerView.$children[0].fetchData()
            }
          }
          if (this.$refs.routerView.$children && this.$refs.routerView.$children.length > 0) {
            this.$refs.routerView.$children.forEach(dv => {
              if (dv && dv.updateReference) {
                dv.updateReference()
              }
            })
          }
        }, 1000)
      }

      if (window.dataViewInstList != undefined && window.dataViewInstList.length > 0) {
        // 清除表格提示，快速切换菜单的时候，表格提示不会自动关闭掉
        window.dataViewInstList.forEach(item => {
          item.clostTooltip()
        })
      }

      this.utils.updateUserState('routeCurrent', this.$route.path)
    }
  },
  components: {
    menuItem,
    homeHeader,
    TagsView,
    FortenPrintForm,
    FortenPrintLabel,
    PrintLabelDevice,
    FortenPrintReport,
    FortenImport,
    inOrderBarcode,
    Report,
    indexModel,
    treeOfficeDrawer,
    pdf
  }
}
</script>
